      COMPLEX*16 FUNCTION CDTAN(Z)
C
C     THIS FUNCTION EVALUATES THE COMPLEX TAN OF Z WHEN Z HAS
C     A NEGATIVE IMAGINARY PART WITH A LARGE ABSOLUTE VALUE.
C 
      IMPLICIT REAL*8 (A-H,O-Z)
      COMPLEX*16 Z,U,V
      COMPLEX*16 CI
      REAL*8 X,Y,SNEG,DREAL
C
      SNEG=-44.368D0
      CI=DCMPLX(0.0D0,1.0D0)
      X=DREAL(Z)
      Y=DIMAG(Z)
C
C     EXP(2.*(-44.368)) SHOULD UNDERFLOW TO ZERO GIVING CDTAN=-CI.
C     THIS IS A MACHINE DEPENDENT CONSTANT
C
      CDTAN=-CI
      IF(Y .LT. SNEG) GO TO 100
C 
      U=2.0D0*Y-CI*X
      V=CI*X
C
      CDTAN=CI*(CDEXP(U)-CDEXP(V))/(CDEXP(U)+CDEXP(V))
C
  100 CONTINUE
      RETURN
      END      
